<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:ez="http://java.sun.com/jsf/composite/ezcomp"
                xmlns:pe="http://primefaces.org/ui/extensions">


    <ui:define name="content">

        <h:panelGroup rendered="true" >
            <h:form>
                <p:panel id="reportPrint" styleClass="noBorder summeryBorder" header="Purchase Bill Item Report">
                    <p:panelGrid columns="2" style="noPrintButton">
                        <h:outputLabel value="From Date"/>
                        <p:calendar styleClass="dateTimePicker" id="frmDate" value="#{commonReport.fromDate}" navigator="true"  pattern="dd MMMM yyyy HH:mm:ss" >
                        </p:calendar>

                        <h:outputLabel value="To Date"/>
                        <p:calendar styleClass="dateTimePicker" id="toDate" value="#{commonReport.toDate}" navigator="true" pattern="dd MMMM yyyy HH:mm:ss" >
                        </p:calendar>

                        <h:outputLabel  value="Department"  />
                        <p:autoComplete  value="#{commonReport.department}"  
                                         completeMethod="#{departmentController.completeDept}" var="dept"
                                         itemValue="#{dept}" itemLabel="#{dept.name}" 
                                         forceSelection="true" rendered="true"
                                         requiredMessage="You must select a department" >
                        </p:autoComplete>

                        <h:outputLabel  value="Payment Methord"  />
                        <p:selectOneMenu   id="pay" value="#{commonReport.paymentMethod}">     
                            <f:selectItem itemLabel="Select Payment Methord" />
                            <f:selectItems value="#{enumController.paymentMethodsForPo}"  />
                        </p:selectOneMenu>

                    </p:panelGrid>

                    <h:panelGrid columns="3">
                        <p:commandButton id="btnRefresh" ajax="false" value="Fill" 
                                         styleClass="noPrintButton" 
                                         actionListener="#{commonReport.createDirectPurchaseBillItemTable()}"
                                         style="float: right;" /> 

                        <p:commandButton actionListener="#{commonReport.createDirectPurchaseBillItemTable()}" ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                            <pe:exporter type="xlsx" target="billed,cancelled,refunded" fileName="report_grn_detail_by_supplier"  />
                        </p:commandButton>

                        <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" 
                                         style="float: right;" >
                            <p:printer target="reportPrint"/>
                        </p:commandButton>
                    </h:panelGrid>



                    <h:panelGrid columns="2" styleClass="printBlock" style="min-width: 100%;">

                        <h:outputLabel value="GRN Detailed Report "/>
                        <h:outputLabel/>
                        <h:outputLabel value="Institution "/>
                        <h:outputLabel value="#{commonReport.department.institution.name}"/>
                        <h:outputLabel value="Department "/>
                        <h:outputLabel value="#{commonReport.department.name}"/>
                        <h:outputLabel value="From" />
                        <h:outputLabel  value="#{commonReport.fromDate}" >
                            <f:convertDateTime pattern="dd MM yy hh:mm:ss a"/>
                        </h:outputLabel>                          
                        <h:outputLabel value="To"/>
                        <h:outputLabel  value="#{commonReport.toDate}" style="float: right" >
                            <f:convertDateTime pattern="dd MM yy hh:mm:ss a"/>
                        </h:outputLabel>
                    </h:panelGrid>


                    <p:dataTable id="billed"  value="#{commonReport.billItems}" var="bi" 
                                 rendered="#{commonReport.billItems.size()!=0}" >

                        <f:facet name="header">  
                            <h:outputLabel value="Purchase"/>
                        </f:facet>

                        <p:column headerText="Purchase No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Purchase No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.deptId}"/>
                        </p:column>

                        <p:column headerText="Can. No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Can. No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.cancelledBill.deptId}"/>
                        </p:column>

                        <p:column headerText="Invoice No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Invoice No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.invoiceNumber}"/>
                        </p:column>

                        <p:column headerText="Created At"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Created At"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.createdAt}" >
                                <f:convertDateTime pattern="dd MM yy hh:mm:ss a"/>
                            </h:outputLabel>
                        </p:column>

                        <p:column headerText="Suplier Name"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Suplier Name"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.fromInstitution.name}"/>

                        </p:column>

                        <p:column headerText="Department" rendered="#{commonReport.department eq null}">
                            <f:facet name="header">  
                                <h:outputLabel value="Department"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.department.name}"/>
                        </p:column>

                        <p:column headerText="Payment Methord" rendered="#{commonReport.paymentMethod eq null}">
                            <f:facet name="header">  
                                <h:outputLabel value="Payment Methord"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.paymentMethod}"/>
                        </p:column>

                        <p:column style=" text-align: left"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Item"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.item.name}" />
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Purchase Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.purchaseRate}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Sale Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.retailRate}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Qty"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.qty}" >
                                <f:convertNumber pattern="#,##0"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Free Qty"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.freeQty}" >
                                <f:convertNumber pattern="#,##0"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.netValue}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                    </p:dataTable>

                    <p:spacer height="30"/>

                    <p:dataTable id="cancelled"  value="#{commonReport.canBillItems}" var="bi" 
                                 rendered="#{commonReport.billItems.size()!=0}" >

                        <f:facet name="header">  
                            <h:outputLabel value="Purchase Cancel"/>
                        </f:facet>

                        <p:column headerText="Cancel No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Cancel No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.deptId}"/>
                        </p:column>

                        <p:column headerText="Bill. No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Bill. No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.billedBill.deptId}"/>
                        </p:column>

                        <p:column headerText="Invoice No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Invoice No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.invoiceNumber}"/>
                        </p:column>

                        <p:column headerText="Created At"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Created At"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.createdAt}" >
                                <f:convertDateTime pattern="dd MM yy hh:mm:ss a"/>
                            </h:outputLabel>
                        </p:column>

                        <p:column headerText="Suplier Name"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Suplier Name"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.fromInstitution.name}"/>

                        </p:column>

                        <p:column headerText="Department" rendered="#{commonReport.department eq null}">
                            <f:facet name="header">  
                                <h:outputLabel value="Department"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.department.name}"/>
                        </p:column>

                        <p:column headerText="Payment Methord" rendered="#{commonReport.paymentMethod eq null}">
                            <f:facet name="header">  
                                <h:outputLabel value="Payment Methord"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.paymentMethod}"/>
                        </p:column>

                        <p:column style=" text-align: left"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Item"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.item.name}" />
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Purchase Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.purchaseRate}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Sale Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.retailRate}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Qty"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.qty}" >
                                <f:convertNumber pattern="#,##0"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Qty"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.freeQty}" >
                                <f:convertNumber pattern="#,##0"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.netValue}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                    </p:dataTable>

                    <p:spacer height="30"/>

                    <p:dataTable id="refunded"  value="#{commonReport.refBillItems}" var="bi" 
                                 rendered="#{commonReport.billItems.size()!=0}" >

                        <f:facet name="header">  
                            <h:outputLabel value="Purchase Return"/>
                        </f:facet>

                        <p:column headerText="Retuen No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Retuen No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.deptId}"/>
                        </p:column>

                        <p:column headerText="Bill. No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Bill. No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.billedBill.deptId}"/>
                        </p:column>

                        <p:column headerText="Invoice No" >
                            <f:facet name="header">  
                                <h:outputLabel value="Invoice No"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.invoiceNumber}"/>
                        </p:column>

                        <p:column headerText="Created At"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Created At"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.createdAt}" >
                                <f:convertDateTime pattern="dd MM yy hh:mm:ss a"/>
                            </h:outputLabel>
                        </p:column>

                        <p:column headerText="Suplier Name"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Suplier Name"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.fromInstitution.name}"/>

                        </p:column>

                        <p:column headerText="Department" rendered="#{commonReport.department eq null}">
                            <f:facet name="header">  
                                <h:outputLabel value="Department"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.department.name}"/>
                        </p:column>

                        <p:column headerText="Payment Methord" rendered="#{commonReport.paymentMethod eq null}">
                            <f:facet name="header">  
                                <h:outputLabel value="Payment Methord"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.bill.paymentMethod}"/>
                        </p:column>

                        <p:column style=" text-align: left"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Item"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.item.name}" />
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Purchase Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.purchaseRate}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Sale Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.retailRate}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Qty"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.qty}" >
                                <f:convertNumber pattern="#,##0"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Qty"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.pharmaceuticalBillItem.freeQty}" >
                                <f:convertNumber pattern="#,##0"/>
                            </h:outputLabel>
                        </p:column>
                        <p:column style=" text-align: right"  >
                            <f:facet name="header">  
                                <h:outputLabel value="Value"/>
                            </f:facet> 
                            <h:outputLabel value="#{bi.netValue}" >
                                <f:convertNumber pattern="#,##0.00"/>
                            </h:outputLabel>
                        </p:column>
                    </p:dataTable>

                    <p:spacer height="30"/>

                </p:panel>
            </h:form>
        </h:panelGroup>
    </ui:define>

</ui:composition>
